import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/2 21:04
 * 星际密码
 * 数根
 */
public class Day25 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        while (s.hasNext()){
            String num = s.nextLine();
            System.out.println(numRoot(num));
        }
    }

    //------------------------------------------
    public static String numRoot(String num){
        if (num.length()==1){
            return num;
        }
        int sum = 0;
        char[] ch = num.toCharArray();
        for (int i = 0; i < num.length(); i++) {
            sum += ch[i]-'0';
        }

        return numRoot(String.valueOf(sum));
    }
    //-----------------------------------------斐波那契变形！
    public static void main1(String[] args) {
        Scanner s = new Scanner(System.in);

        while (s.hasNext()) {
            int count = s.nextInt();
            while (count > 0) {
                int n = s.nextInt();
                System.out.printf("%04d", fib(n) % 10000);
                count--;
            }
            System.out.println();
        }

    }
    public static int  fib (int num){
        int fn2 = 0;
        int fn1 = 1;
        int fn = 1;
        for (int i = 0; i < num; i++) {
            fn = (fn1+fn2)%10000;
            fn2 = fn1 %10000 ;
            fn1=fn%10000;
        }
        return fn;
    }
}
